#!/bin/bash

# 注意事项：
# 1）每次只保存4900行的最后200行（lt.cfg参数文件需要适当修改）
# 2）save_wave代码需要修改保存的行数

OUTDIR=dcds_extractor/WF-2023-11-07-500kHz

if [ -d {OUTDIR} ]; then
    echo "${OUTDIR} already exists."
else
    mkdir -p ${OUTDIR}
fi

ch=1

./readout

while [ ${ch} -le 16 ]
#while [ ${ch} -le 1 ]
do
	echo "> collecting OS waveforms of ch: ${ch}"
	./os_selector ${ch}

    n=1
    while [ $n -le 2 ]
    do
        echo "--> n = $n"
        ./readout
        
        wfile="${OUTDIR}/OS_${ch}_${n}.bin"
        ./save_wave -o ${wfile}

#		echo "touching ${wfile}"
#		touch ${wfile}

    	# 手动释放缓存
		sync
		echo 3 > /proc/sys/vm/drop_caches
        
        n=$((n+1))
    done
    ch=$((ch+1))
done
